package cn.tedu.springboot2106.bean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class Worker {
    private String name = "光头强";
    //Spring 会自动的将Saw对象注入到saw属性中
    //@Autowired
    @Resource(name = "saw")
    //@Qualifier("saw")
    private Saw s;

    //@Autowired //利用构造器注入属性
//    public Worker(Saw saw){
//        System.out.println("Worker()");
//        this.saw = saw;
//    }

    //@Autowired //利用方法注入属性
    //@Resource
    public void setSaw(Saw saw) {
        System.out.println("setSaw()");
        this.s = saw;
    }

    public void work(){
        System.out.println(name+"使用"+s+"砍树");
    }
}
